﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：FeedBackReply.aspx.cs
    // 文件功能描述：消息管理：回复反馈
    // 创建标识：吕海乐2009-5-20
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.MessageManage
{
    public partial class FeedBackReply : BasePage
    {
        public FeedBackReply()
        {
            this.ModuleNo = Module.消息管理.ToString();
            this.PageOperateType = OperateType.写消息.ToString();
        }

        IBLL_Message im = Factory.BLL_Message();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (!string.IsNullOrEmpty(Request.QueryString["fID"]))
                {
                    hdfID.Value = Request.QueryString["fID"];
                    BindFeedBackInfo();
                }
                else
                {
                    PageError("数据已经不存在，请先选择相应的反馈！", this.ReturnUrl);
                }
               
            }
        }

        /// <summary>
        /// 绑定反馈的基本信息
        /// </summary>
        private void BindFeedBackInfo()
        {
           int temp;
           string feedBackID = hdfID.Value;
           Model.View.FeedBack feedBack = im.GetFeedBack_Manager(new HZ.DrugTrade.Model.Query.FeedBack() { FeedBackID = feedBackID }, 1, 0, out temp)[0];
           tdReciever.InnerText=
           tdReciever.InnerText = feedBack.Reciever + "【" + feedBack.ReceiverName + "】";
           hdfReciever.Value = feedBack.Reciever;
           tdTitle.InnerText = Server.HtmlEncode(feedBack.Title).ToString();
           tdSender.InnerText = feedBack.Sender + "【" + feedBack.SenderName + "】";
           hdfSender.Value = feedBack.Sender;
           tdSendTime.InnerText = feedBack.SendTime.ToString();
           tdContent.InnerHtml = feedBack.Content;
           string status = feedBack.Status.ToString();

           trlReplyContent.Visible = false;
           txtReplyContent.Visible = true;

            //已回复
            if (status == "2")
            {
                btnReply.Visible = false;
                trlReplyContent2.Visible = false;
                txtReplyContent.Visible = false;
                trlReplyContent.Visible = true;
                tdReplyContent.InnerHtml = feedBack.Replyer + "【" + feedBack.ReceiverName + "】<B>回复于</B>" + feedBack.ReplyTime+ "<hr><br/>"+feedBack.Reply   ;
            }
            else if (status != "1") //未阅读
            {
                //将反馈的状态先刷新为已阅读，绑定反馈的基本信息
                SetFeedBackStatus(1);
            }
        }

        /// <summary>
        /// 刷新反馈的状态
        /// </summary>
        /// <param name="status">1：已阅读；2：已回复</param>
        private void SetFeedBackStatus(int status)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["fID"]))
            {
                hdfID.Value = Request.QueryString["fID"];
                FeedBack aFeedBack = new FeedBack();
                aFeedBack.FeedBackID = hdfID.Value;
                aFeedBack.Status = status;
                int flag = im.UpdateFeedBack_Status(aFeedBack);
                if (flag != 1)
                {
                    PageError("反馈状态更新失败！", this.ReturnUrl);
                }
            }
            else
            {
                PageError("数据已经不存在，请先选择相应的反馈！", this.ReturnUrl);
            }
        }

        /// <summary>
        /// 回复反馈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnReply_Click(object sender, EventArgs e)
        {
            //回复内容不能为空
            if (string.IsNullOrEmpty(txtReplyContent.Value))
            {
                HZ.Web.WebUtil.Alert("回复内容不能为空！", this);
                return;
            }

            FeedBack aFeedBack = new FeedBack();
            aFeedBack.FeedBackID = hdfID.Value;
            aFeedBack.Reply = txtReplyContent.Value;
            aFeedBack.Replyer = CurrentAccount.GetUser().UserID;
            aFeedBack.ReplyTime = DateTime.Now;
            aFeedBack.Status = 2;
            int flag = im.ReplyFeedBack(aFeedBack);
            if (flag == 1)
            {
                PageInfo("回复成功！", "FeedBackList.aspx");
            }
            else
            {
                PageError("回复失败！", this.ReturnUrl);
            }
        }
    }
}
